package com.spzx.JUC3.test1;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo01 {
    public static void main(String[] args) {
        //1.創建countDownLatch對象
        CountDownLatch countDownLatch = new CountDownLatch(2);

        //2.创建线程任务类对象，并且把这个CountDownLatch对象作为构造方法的参数进行传递
        //CountDownLatch'Demo01' countDownLatchDemo01 = new CountDownLatchThread01(countDownLatch);
        CountDownLatchThread01 countDownLatchThread01 = new CountDownLatchThread01(countDownLatch);

        //3. 创建线程任务类对象，并且把这个CountDownLatch对象作为构造方法的参数进行传递
        CountDownLatchThread02 countDownLatchThread02 = new CountDownLatchThread02(countDownLatch);

        //4.啓動綫程
        Thread t1 = new Thread(countDownLatchThread01);
        Thread t2 = new Thread(countDownLatchThread02);
        t1.start();
        t2.start();

        //  5. 在主线程中调用 CountDownLatch中的await让主线程处于阻塞状态
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        //输出程序
        System.out.println("主线程执行完毕");


    }
}
